<!DOCTYPE HTML>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
    <title>绑定提现银行卡</title>
    <meta name="format-detection" content="telephone=no" />
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no">
    <link rel="stylesheet" href="../css/bui.css" />
</head>
<body>
<style>
    .page-form .bui-fluid-space-3 .span1 {
        margin-bottom: .2rem;
    }

    .selected-val {
        margin-right: .1rem;
    }
</style>
<div class="bui-page page-form">
    <header class="bui-bar">
        <div class="bui-bar-left"> <a class="bui-btn btn-back" id="backupButton" ><i class="icon-back"></i></a> </div>
        <div class="bui-bar-main">绑定提现银行卡</div>
        <div class="bui-bar-right"> </div>
    </header>
    <main>
        <div class="bui-list">
            <label class="bui-btn bui-box">
                <div class="bui-label">会员代码</div>
                <div class="span1">
                    <div class="bui-value" id="code">&nbsp;</div>
                </div>
            </label>
            <label class="bui-btn bui-box">
                <div class="bui-label">姓名</div>
                <div class="span1">
                    <div class="bui-value" id="xm">&nbsp;</div>
                </div>
            </label>
            <label class="bui-btn bui-box">
                <div class="bui-label">身份证号</div>
                <div class="span1">
                    <div class="bui-value" id="sfzh">&nbsp;</div>
                </div>
            </label>
            <label class="bui-btn bui-box">
                <div class="bui-label">手机号</div>
                <div class="span1">
                    <div class="bui-value" id="mobile">&nbsp;</div>
                </div>
            </label>
            <label class="bui-btn bui-box">
                <div class="bui-label"><font color="red">*</font>银行卡号</div>
                <div class="span1">
                    <div class="bui-input user-input">
                        <input id="memberAcctNo" type="number" value="" placeholder="请输入银行卡号">
                    </div>
                </div>
            </label>
            <label class="bui-btn bui-box" id="acctOpenBranchName">
                <label><font color="red">*</font>开户行</label>
                <div class="span1"></div>
                <i class="icon-listright"></i>
            </label>



        </div>
        <div class="container-y">
            <div class="bui-box-space">
                <div class="span1">
                    <div class="bui-btn round primary" id="submit">提交</div>
                </div>
            </div>
        </div>

        <div id="dialogCenter" class="bui-dialog" style="display: none;">
            <div class="bui-dialog-head">手机验证码验证</div>
            <div class="bui-dialog-main">
                <label class="bui-btn bui-box clearactive">
                    <label class="bui-label">验证码:</label>
                    <div class="span1">
                        <input type="text" id="messagecheckcode" class="bui-input" value="" placeholder="请输入验证码" maxlength="6">
                    </div>
                    <div class="bui-btn primary-reverse mini ring" id="btnSend">发送验证码</div>
                </label>
            </div>
            <div class="bui-dialog-foot">
                <div class="bui-box">
                    <div class="span1">
                        <div class="bui-btn">取消</div>
                    </div>
                    <div class="span1">
                        <div id="bindsmsok" class="bui-btn blue">确定</div>
                    </div>
                </div>
            </div>
            <div class="bui-dialog-close"><i class="icon-close"></i></div>
        </div>

        <div id="dialogFull" class="bui-dialog" style="display: none;">
            <div class="bui-dialog-head">协议</div>
            <div class="bui-dialog-main">
                <iframe src="https://my.orangebank.com.cn/orgLogin/hd/act/jianzb/jzbxy.html" frameborder="0" style="width: 100%" height="100%" ></iframe>
            </div>
            <div class="bui-dialog-foot">
                <div class="bui-box">
                    <div class="span1">
                        <div class="bui-btn">取消</div>
                    </div>
                    <div class="span1">
                        <div class="bui-btn blue">同意</div>
                    </div>
                </div>
            </div>
            <div class="bui-dialog-close"><i class="icon-close"></i></div>
        </div>

    </main>
</div>
    <!-- 依赖库 手机调试的js引用顺序如下 -->
    <script src="../js/zepto.js"></script>
    <script src="../js/plugins/fastclick.js"></script>
    <script src="../js/bui.js"></script>
    <script src="../js/common.js"></script>
    <script>
        bui.ready(function () {
            initCommon(bui);
            var uiParams = bui.getPageParams();
            var user = $$("user");
            $("#code").html($$("membercode"));
            $("#xm").html(user.xm||'');
            $("#sfzh").html(user.idcard||'');
            $("#mobile").html(user.mobile||'');

            bui.btn({id: ".bui-page", handle: ".bui-btn"}).load();

            var uiSelect;

            var uiSelectAjax = bui.ajax({
                url: BASE_URL+"pig/t-jzb-yhmc/getyhmclist",
                // data: {
                //     yhmc:user.subno
                // },
                method: "GET"
            });
            uiSelectAjax.then(function(res) {
                if(res.code == '10000'){
                    var uiselect_data = res.data;
                    uiSelect = bui.select({
                        trigger: "#acctOpenBranchName",
                        title: "请选择开户行",
                        type: "checkbox",
                        needSearch: true,
                        // height: 300,
                        data: uiselect_data,
                        // value: ["广东", "上海"],
                        //如果需要点击再进行操作,增加按钮
                        buttons: [{ name: "重置", className: "" }, { name: "确定", className: "primary-reverse" }],
                        callback: function(e) {

                            var text = $(e.target).text();
                            if (text == "重置") {
                                uiSelect.selectNone();
                            } else {
                                uiSelect.clearSearch();
                                uiSelect.hide();
                            }
                        },
                        onChange: function(e) {
                            // console.log(e)
                        }
                    });

                }
            },function(res) {
                bui.alert("请求异常");
            });


            $("#bindsmsok").on("click",function () {
                var memberAcctNo = $("#memberAcctNo").val();
                var messagecheckcode = $("#messagecheckcode").val();
                if(messagecheckcode!=''){

                    var bindsmsAjax = bui.ajax({
                        url: BASE_URL+"pig/t-jzb-bindcard/jzbbindcardsms",
                        data: {
                            subacctno:user.subno,
                            trannetmembercode:user.membercode,
                            memberacctno:memberAcctNo,
                            messagecheckcode:messagecheckcode
                        },
                        method: "POST"
                    });
                    bindsmsAjax.then(function(res) {
                        if(res.code=='10000'){
                            bui.alert("绑卡成功！", function(e){
                                window.location.href = "bank.html";
                            });
                        }else{
                            bui.alert(res.message, function(e){

                            });
                        }

                    },function(res) {
                        bui.alert("请求异常");
                    });

                }
            });

            $("#bindsmscancel").on("click",function () {
                uiDialog.close();
            });

            // 倒计时
            // var timer = bui.timer({
            //     target: ".timedown",
            //     onProcess: function(param) {
            //         console.log(param)
            //     },
            //     onEnd: function(e) {
            //         $(e.target).text("确认");
            //         $(e.target).parent().click(function() {
            //             uiDialog.close();
            //         })
            //     },
            //     // type: "second",
            //     time: 5
            // })

            // 自定义居中弹出框
            var $btnSend = $("#btnSend");

            var uiDialog = bui.dialog({
                id: "#dialogCenter",
                height: 300,
                autoClose: false,
                callback: function(e) {
                    // console.log(e.target)
                }
            }).on("open", function() {
                if (timer) {
                    timer.start();
                    timer = null;
                }
            });
            var timer = bui.timer({
                onEnd: function() {
                    bui.alert("验证码已超期，请重新提交获取验证码！");
                    uiDialog.close();
                },
                onProcess: function(e) {
                    var valWithZero = e.count < 120 ? "0" + e.count : e.count;
                    $btnSend.text(valWithZero + "后重新获取");
                },
                time: 120
            });
            $("#submit").on("click", function (argument) {


                var uiDialogFull = bui.dialog({
                    id: "#dialogFull",
                    position: "top",
                    fullscreen: true,
                    useBox: true,
                    buttons: [],
                    callback:function (e){
                        var text = $(e.target).text();
                        if (text == "同意") {
                            window.location.href = "bindtx.html";
                        }
                        this.close()
                    }
                });
                uiDialogFull.open();
                return ;

                var memberAcctNo = $("#memberAcctNo").val();
                  // var acctOpenBranchName = $("#acctOpenBranchName").val();
                if(memberAcctNo == ""){
                    bui.alert("请输入银行卡号！");
                    return ;
                }
                if(uiSelect.value() == ""){
                    bui.alert("请选择开户行！");
                    return ;
                }
                var acctopenbranchname = uiSelect.text();
                var cnapsbranchid = uiSelect.value();
                var eiconbankbranchid = uiSelect.value();

                bui.confirm("确定要绑定银行卡么？", function(e) {
                    var text = $(e.target).text();
                    if (text == "确定") {
                        //执行登录操作
                        //调用绑卡接口
                        var bindAjax = bui.ajax({
                            url: BASE_URL+"pig/t-jzb-bindcard/jzbbindcard",
                            data: {
                                subacctno:user.subno,
                                trannetmembercode:user.membercode,
                                membername:user.xm,
                                memberglobalid:user.idcard,
                                memberacctno:memberAcctNo,
                                acctopenbranchname:acctopenbranchname,
                                cnapsbranchid:cnapsbranchid,
                                eiconbankbranchid:eiconbankbranchid,
                                mobile:user.mobile,
                                yhbm:user.yhbm
                            },
                            method: "POST"
                        });
                        bindAjax.then(function(res) {
                            if(res.code=='10000'){
                                bui.alert(res.message, function(e){
                                    uiDialog.open();
                                    var hasDisabled = $btnSend.hasClass("disabled");
                                    if (!hasDisabled) {
                                        $btnSend.addClass("disabled")
                                        bui.hint("验证码发送成功")
                                        timer.restart();
                                    }
                                    // console.log("你点击了" + $(e.target).text())

                                });
                            }else{
                                bui.alert(res.message, function(e){

                                });
                            }

                        },function(res) {
                            bui.alert("请求异常");
                        });


                    }
                    this.close()
                });
            });

            $("#backupButton").on("click", function (argument) {
                window.location.href = "home.html";
            });


        })
    </script>
</body>
</html>